package com.example.introductiontoprogramming;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

public class Programming4 extends AppCompatActivity {


    private EditText edtTxtMaina;
    private Button btnMainJisuan;
    private TextView tvMainResult;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.programming_main4);

        initView();
    }

    private void initView() {
        edtTxtMaina = (EditText) findViewById(R.id.edtTxtMaina);
        btnMainJisuan = (Button) findViewById(R.id.btnMainJisuan);
        tvMainResult = (TextView) findViewById(R.id.tvMainResult);
    }

    public void resultonClick(View view) {
        String num = edtTxtMaina.getText().toString();
        if (num.length()==0){
            Toast.makeText(Programming4.this, "请输入度数", Toast.LENGTH_SHORT).show();
        }else {
            double F = Double.parseDouble(num);
            double c = 0;
            c = 5 * (F - 32) / 9;
            String str = String.format("%.2f", c);
            tvMainResult.setText(str);
        }
    }

}